package com.lpf.lambda;

import org.junit.Test;

import java.util.Comparator;
import java.util.function.Consumer;

public class Lambda_Syntax {

    @Test
    public void test1() {
        int num = 0;// JDK 7 前，必须显示添加 final，但从JDK 8 开始，编译器会自动添加

        Runnable r = () -> System.out.println("Hello World!" + num);
        r.run();

        System.out.println("-------------------------------");

        Runnable r1 = () -> System.out.println("Hello Lambda!");
        r1.run();
    }

    @Test
    public void test2() {
        Consumer<String> con = System.out::println;
        con.accept("挖坑埋你");
    }

    @Test
    public void test4() {
        Comparator<Integer> com = (x, y) -> {
            System.out.println("com/lpf/functional");
            return Integer.compare(x, y);
        };

        int result = com.compare(1, 2);
        System.out.println(result);
    }

    @Test
    public void test5() {
        Comparator<Integer> com = Integer::compare;
        int result = com.compare(1, 2);
        System.out.println(result);
    }
}
